package test;
/*下拉框、
 * 列表框、
 * 滚动窗格组件*/

import javax.swing.*;
import java.awt.*;

public class demo8 extends JFrame {
    JPanel panel;
    JLabel label;
	JComboBox comboBox;

    public static void main(String[] args) {
        demo8 demo = new demo8();
    }

    public demo8() {
        panel = new JPanel();
        label = new JLabel("你的籍贯：");
        String[] option = {"baijing", "shanghai", "tianjin", "hubei"};
        comboBox = new JComboBox(option);
        comboBox.setEditable(true);
        //设置布局
        this.setLayout(new GridLayout(3, 1));
        //添加组件
        panel.add(label);
        panel.add(comboBox);
        this.add(panel);

        System.out.println(this.comboBox.getSelectedItem());
        this.comboBox.addItem("hello");
        this.setSize(300, 300);
        this.setLocation(300, 500);
        this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
        this.setVisible(true);
    }

}